package com.zbkj.dal.pojo.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.zbkj.dal.common.BigDecimalSerializer;
import com.zbkj.dal.pojo.vo.LogisticsResultVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;
import java.util.List;

/**
 * 订单移动端详情响应对象
 * +----------------------------------------------------------------------
 * | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 * +----------------------------------------------------------------------
 * | Author: CRMEB Team <admin@crmeb.com>
 * +----------------------------------------------------------------------
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "OrderFrontDetailResponse对象", description = "订单移动端详情响应对象")
public class OrderFrontDetailResponse implements Serializable {

    private static final long serialVersionUID = -4324222121352855551L;

    @ApiModelProperty(value = "订单ID")
    private Integer id;

    @ApiModelProperty(value = "订单号")
    private String orderNo;

    @ApiModelProperty(value = "商户ID")
    private Integer merId;

    @ApiModelProperty(value = "用户id")
    private Integer uid;

    @ApiModelProperty(value = "订单商品总数")
    private Integer totalNum;

    @ApiModelProperty(value = "商品总价")
    private BigDecimal proTotalPrice;

    @ApiModelProperty(value = "邮费")
    private BigDecimal totalPostage;

    @ApiModelProperty(value = "订单详情-运费")
    private String totalPostageDesc;

    @ApiModelProperty(value = "订单总价")
    private BigDecimal totalPrice;

    @ApiModelProperty(value = "优惠券金额")
    private BigDecimal couponPrice;

    @ApiModelProperty(value = "使用雅识")
    private Integer useIntegral;

    @ApiModelProperty(value = "雅识抵扣金额")
    private BigDecimal integralPrice;

    @ApiModelProperty(value = "实际支付金额")
    private BigDecimal payPrice;

    @ApiModelProperty(value = "支付邮费")
    private BigDecimal payPostage;

    @ApiModelProperty(value = "支付状态")
    private Boolean paid;

    @ApiModelProperty(value = "支付时间")
    private Date payTime;

    @ApiModelProperty(value = "支付方式:weixin,alipay,yue")
    private String payType;

    @ApiModelProperty(value = "订单状态（0：待支付，1：待发货,2：待收货,3：已收货,4：已完成，5：待核销，9：已取消）")
    private Integer status;

    @ApiModelProperty(value = "订单状态描述", example = "等待您付款")
    private String statusDesc;

    @ApiModelProperty(value = "订单状态备注", example = "订单将于2023-11-1923:18:57自动关闭")
    private String statusRemark;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "订单类型:0-普通订单，1-视频号订单,2-秒杀订单 10:承享订单")
    private Integer type;

    @ApiModelProperty(value = "商户优惠券金额")
    private BigDecimal merCouponPrice;

    @ApiModelProperty(value = "平台优惠券金额")
    private BigDecimal platCouponPrice;

    @ApiModelProperty(value = "发货类型 配送方式 1=快递发货 ，2=门店自提", example = "1")
    private Integer deliverType;

    @ApiModelProperty(value = "发货类型描述", example = "快递到家")
    private String deliverTypeDesc;

    @ApiModelProperty(value = "订单备注", example = "测试订单备注")
    private String remark;

    @ApiModelProperty(value = "能否显示申请退款 0-否/1-是")
    private Integer canRefund;

    // 原信息

    @ApiModelProperty(value = "订单详情")
    private List<MerchantOrderFrontDetailResponse> merchantOrderList;

    // ------------- 补充 -------------

//    @ApiModelProperty(value = "订单商品信息")
//    private OrderDetailResponse orderDetailResponses;
//
//    @ApiModelProperty("商户订单信息")
//    private MerchantOrderFrontDetailResponse merchantOrderResponse;

    @ApiModelProperty("上门自提信息")
    private InStoreAppt orderDeliveryInStoreAppt;

    @ApiModelProperty("订单物流信息")
    private List<LogisticsResultVo> orderLogisticsResponse;

    @ApiModelProperty("订单各阶段时间")
    private StepsTime stepsTime;

    @ApiModelProperty("承享归还相关信息")
    private RentReturn rentReturn;

    @ApiModelProperty("订单状态时间日志")
    private OrderStatusExt orderStatusExt;

    @ApiModelProperty
    private OverduePaymentVo overduePaymentVo;

    // 以下是 内部类

    @Data
    @ApiModel("超时费用")
    public static class OverduePaymentVo {

        @ApiModelProperty("总计超时天数")
        private Integer overdueDays;

        @ApiModelProperty("抵扣的雅识费用")
        private BigDecimal integralAmount;

        @ApiModelProperty("超时支付金额")
        private BigDecimal overdueAmount;

        @ApiModelProperty("超时信息")
        private String overdueMessage;
    }

    @Data
    @ApiModel("商品信息")
    public static class OrderDetailResponse {

        @ApiModelProperty(value = "商品名称")
        private String productName;

        @ApiModelProperty(value = "商品图片")
        private String image;

        // ------------------- 购买信息 -------------------

        @ApiModelProperty(value = "实际支付金额")
        @JsonSerialize(using = BigDecimalSerializer.ConvertToString.class)
        private BigDecimal payAmount;

        @ApiModelProperty(value = "购买数量")
        private Integer quantity;

        @ApiModelProperty(value = "单位名称")
        private String unitName;


        // ------------------- 承享信息 -------------------

        @ApiModelProperty(value = "承享天数")
        private Integer rentDays;

        @ApiModelProperty(value = "承享价格")
        private BigDecimal rentPrice;
    }


    @Data
    @ApiModel("承享归还相关信息")
    public static class RentReturn {
        @ApiModelProperty(value = "承享归还类型(如果是承享订单才有)", notes = "pickup:上门取件 store:到店归还")
        private String rentReturnType;

        @ApiModelProperty("预约取件信息")
        private PickUpAppt pickUpAppt;

        @ApiModelProperty("到店归还信息")
        private InStoreAppt inStoreAppt;
    }

    @Data
    @ApiModel("预约取件")
    @EqualsAndHashCode(callSuper = true)
    public static class PickUpAppt extends ReturnBase {

        @ApiModelProperty(value = "快递名称", example = "顺丰快递")
        private String deliveryName;

        @ApiModelProperty(value = "取件码", example = "2039")
        private String pickupCode;

        @ApiModelProperty(value = "寄件人名称", example = "张三")
        private String senderName;

        @ApiModelProperty(value = "寄件人电话", example = "12821092321")
        private String senderPhone;

        @ApiModelProperty(value = "寄件人地址", example = "上海市**区")
        private String senderAddress;

    }

    @Data
    @ApiModel("上门取件")
    @EqualsAndHashCode(callSuper = true)
    public static class InStoreAppt extends ReturnBase {

        @ApiModelProperty("自提码")
        private String selfCode;

        @ApiModelProperty("预约记录号")
        private String reservationNo;

        @ApiModelProperty("商户名称")
        private String name;

        @ApiModelProperty("手机号")
        private String phone;

        @ApiModelProperty("地址")
        private String address;

        @ApiModelProperty("纬度")
        private String latitude;

        @ApiModelProperty("经度")
        private String longitude;
    }

    @Data
    @ApiModel("预约时间展示基础数据")
    public static class ReturnBase {

        @ApiModelProperty(value = "日期描述", example = "今天")
        private String dateDesc;

        @ApiModelProperty(value = "取件时间段", example = "09:00:00")
        @JsonFormat(pattern = "HH:mm")
        @DateTimeFormat(pattern = "HH:mm")
        private LocalTime startTime;

        @ApiModelProperty(value = "取件时间段", example = "09:00:00")
        @JsonFormat(pattern = "HH:mm")
        @DateTimeFormat(pattern = "HH:mm")
        private LocalTime endTime;
    }

    @Data
    @ApiModel("各步骤时间点")
    public static class StepsTime {

        // 创建时间
        @ApiModelProperty(value = "创建时间")
        private LocalDateTime createTime;

        // 支付时间
        @ApiModelProperty(value = "支付时间")
        private LocalDateTime payTime;

        // 收货时间
        @ApiModelProperty(value = "收货时间")
        private LocalDateTime deliveryTime;

        // 归还时间
        @ApiModelProperty(value = "归还时间")
        private LocalDateTime returnTime;

        // 取消时间
        @ApiModelProperty(value = "取消时间")
        private LocalDateTime cancelTime;
    }

    @Data
    @ApiModel("订单状态时间")
    public static class OrderStatusExt {

        /**
         * @see TimeType
         */
        @ApiModelProperty("类型")
        private TimeType type;

        @ApiModelProperty("时间点1")
        private LocalDateTime time1 = LocalDateTime.now();

        @ApiModelProperty("时间点2")
        private LocalDateTime time2 = LocalDateTime.now();

        @ApiModelProperty("剩余天数")
        private long remainingDays;
    }

    public enum TimeType {

        // 订单自动关闭时间
        AUTO_CLOSE,
        // 平台发货时间
        PLAT_DELIVERY,
        // 自动签收时间
        AUTO_RECEIPT,
        // 承享中
        RENTING,
        // 用户归还发货时间
        USER_RETURN_DELIVERY,
        // 平台收货时间
        PLANT_RETURN_RECEIPT,

        // 承享超时
        RENT_OVERDUE,
        ;


    }

}
